package com.example.manager;

import com.example.entity.Dept;
import com.example.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DeptManager2 {

    @Autowired
    private DeptMapper deptMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    /**
     * 内层使用propagation = Propagation.REQUIRES_NEW
     * 开启新事物，只有内层会回滚。外层会try——catch不会在回滚，所以外层的循环会继续执行。
     */
   // @Transactional()
    /**
     * 内岑使用默认的propagation，发生混滚后会带着外层一起回滚，且外层的循环不在继续执行；
     */
    public void insertDept(Dept dept){
        deptMapper.insert(dept);
        System.out.println(10/0);
    }

    public void insertDept(Dept dept,String str){
        deptMapper.insert(dept);
       // System.out.println(10/0);
    }
}
